package laba5;

import interfaces.task2.FractionNumber;
import interfaces.task5.ArrayIterator;

/**
 *
 * @author yakimovich
 */
public class ArrayCollectionDemo {

    /**
     * Demonstration of addition FractionNumberImpl
     *
     * @param args
     */
    public static void main(String[] args) {
        FractionNumberOperationImpl fNO = new FractionNumberOperationImpl();

        ArrayCollectionImpl<FractionNumberImpl> arrayColl = new ArrayCollectionImpl();
        arrayColl.add(new FractionNumberImpl(2, 5));
        arrayColl.add(new FractionNumberImpl(1, 3));
        arrayColl.add(new FractionNumberImpl(0, 7));
        arrayColl.add(new FractionNumberImpl(2, -3));
        arrayColl.add(new FractionNumberImpl(-8, 5));
        arrayColl.add(new FractionNumberImpl(2, 1));
        arrayColl.add(new FractionNumberImpl(-6, 1));
        arrayColl.add(new FractionNumberImpl(-2, -2));
        arrayColl.add(new FractionNumberImpl(0, 9));
        arrayColl.add(new FractionNumberImpl(7, -3));

        FractionNumberImpl sum = new FractionNumberImpl(0, 1);

        ArrayIterator iterator = (ArrayIterator) arrayColl.iterator();
        while (iterator.hasNext()) {
            sum = (FractionNumberImpl) fNO.add(sum, (FractionNumber) iterator.next());
        }
        System.out.println("The sum of all the numbers: " + sum.value());
    }
}
